import { userAccountLogin } from '@/api/user'
const user = {
  namespaced: true, // 开启命名空间
  state: () => ({
    profile: {}
  }),
  mutations: {
    setProfile (state, profile) {
      state.profile = profile
    },
    // 清空数据
    clearProfile (state) {
      state.profile = {}
    }
  },
  actions: {
    // 登录
    async asyncLogin (ctx, { account, password }) {
      // 1. 调用登录接口
      const res = await userAccountLogin({ account, password })
      // 2. 把用户数据通过调用mutation函数存起来
      ctx.commit('setProfile', res.result)
      // 为啥不把把跳转写到这里？
    }
  },
  getters: {}
}

export default user
